var form, $,areaData;

layui.use(['form','layer','upload','laydate','jquery'],function(){
    form = layui.form;
    $ = layui.jquery;
    var layer = parent.layer === undefined ? layui.layer : top.layer,
        upload = layui.upload,
        laydate = layui.laydate;
    function getImg(id){
        layer.open({
            title: "打印",
            shadeClose: false,
            type: 2,
            area: ['60%', '80%'],
            content: 'down.do?tran=word&id='+param
        });
    }
    $.ajax({
        url: '../user.do',
        data: {
            'tran':'select',
            'get':'info',
            'id':'self'
        },
        dataType: 'json',
        type: 'post',
        async: false,
        success: function(data) {
            if (data.permissions>'1'){
                $("#pass").hide();
                $("#refused").hide();
            }
        }
    });

    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return unescape(r[2]); return null; //返回参数值
    }
    var param =  getUrlParam("id");
    var j ;
    $.ajax({
        url: '../activity.do',
        data: {
            'tran':'select',
            'get':'activityInfo',
            'id':param
        },
        dataType: 'json',
        type: 'post',
        success: function(res) {
            console.log(res)
            $("#activityName").val(res.activity.name);
            $("#submittedDay").val(res.activity.submittedDay);
            $("#holdingDay").val(res.activity.holdingDay);
            $("#subDepName").val(res.activity.subDepName);
            $("#depName").val(res.activity.depName);
            console.log(res.activity.distribute)
            if(res.activity.distribute == '2' || res.activity.distribute == '0'){
                $("#pass").hide();
                $("#refused").hide();
            }
            form.render();
            $("#activityInfo").attr("src",'../down.do?tran=word&id='+param);
        }
    });
    $("#activityInfo").click(function () {
        getImg(param)
    })

    $("#pass").click(function () {
        console.log(2);
        $.ajax({
            url:'../activity.do',
            data: {
                tran:'pass',
                id:param
            },
            type:'post',
            success:function (res) {
                if (res.code == '0'){
                    layer.msg(res.msg);
                    parent.location.reload();
                }else {
                    layer.msg(res.msg);
                }
            }
        })
    })
    $("#refused").click(function () {
        $.ajax({
            url:'../activity.do',
            data: {
                tran:'refused',
                id:param
            },
            type:'post',
            success:function (res) {
                if (res.code == '0'){
                    layer.msg(res.msg);
                    parent.location.reload();
                }else {
                    layer.msg(res.msg);
                }
            }
        })
    })
    //选择出生日期
    laydate.render({
        elem: '.eventDay',
        format: 'yyyy-MM-dd',
        trigger: 'click'
    });

})